package com.catsic.mod.convert;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.catsic.mod.entity.Announces;
import com.catsic.mod.entity.ReceiveMessage;
import com.catsic.mod.entity.SendMessage;
import com.catsic.mod.entity.Wservice;
import com.catsic.mod.form.AnnouncesForm;
import com.catsic.mod.form.ReceiveMessageForm;
import com.catsic.mod.form.SendMessageForm;
import com.catsic.mod.form.WserviceForm;

public class Converts extends com.catsic.pub.convert.Converts {
	/**
	 * 
	 * convert:赋值WserviceForm对象.
	 * 
	 * @author zhoukai
	 * @param Wservice
	 * @return WserviceForm
	 */
	public static WserviceForm convert(Wservice wservice) {
		
       if(null==wservice){
    	   return null;
       }
       WserviceForm form = new WserviceForm();
       if(null != wservice.getDrawer()){
    	   form.setType(wservice.getDrawer().getCode());
    	   form.setTypeName(wservice.getDrawer().getName());
       }
       if(null != wservice.getOrgan()){
    	   form.setOrganId(wservice.getOrgan().getId());
    	   form.setOrganCode(wservice.getOrgan().getCode());
    	   form.setOrganName(wservice.getOrgan().getName());
       }
       form.setId(wservice.getId());
       form.setMethodName(wservice.getMethodName());
       form.setName(wservice.getName());
       form.setStatus(wservice.getStatus());
       form.setUrl(wservice.getUrl());
	   return form;
	   
	}
	/**
	 * convert:转换环节信息类
	 * 
	 * @author xiaobin
	 * @param ReceiveMessage
	 * @return  ReceiveMessageForm
	 */
	public static ReceiveMessageForm convert(ReceiveMessage receiveMessage) {
		if(receiveMessage==null){
			return null;
		}
		ReceiveMessageForm receiveMessageForm=new ReceiveMessageForm();
		receiveMessageForm.setReceiveMessageId(receiveMessage.getId());
		receiveMessageForm.setTitle(receiveMessage.getTitle());
		receiveMessageForm.setContent(receiveMessage.getContent());
		receiveMessageForm.setUserId(receiveMessage.getUser().getId());
		receiveMessageForm.setUserName(receiveMessage.getUser().getUsername());
		receiveMessageForm.setAddresseeId(receiveMessage.getAddresseeId());
		receiveMessageForm.setAddresseeName(receiveMessage.getAddresseeName());
		receiveMessageForm.setCode(receiveMessage.getCode());
		receiveMessageForm.setAddresseeTypeName(receiveMessage.getAddresseeTypeName());
		receiveMessageForm.setSendMessageId(receiveMessage.getSendMessage().getId());
		return receiveMessageForm;
	}
	
	/**
	 * @author xiaobin
	 * @param sendMessage
	 * @return sendMessageForm
	 */
	public static SendMessageForm convert(SendMessage sendMessage) {
		if(sendMessage==null){
			return null;
		}
		SendMessageForm sendMessageForm=new SendMessageForm();
		sendMessageForm.setSendMessageId(sendMessage.getId());
		sendMessageForm.setTitle(sendMessage.getTitle());
		sendMessageForm.setContent(sendMessage.getContent());
		sendMessageForm.setUser(sendMessage.getUser());
		sendMessageForm.setUserId(sendMessage.getUser().getId());
		sendMessageForm.setUserName(sendMessage.getUser().getUsername());
		List<String> addresseeIds=new ArrayList<String>();
		List<String> addresseeNames=new ArrayList<String>();
		for (ReceiveMessage receiveMessage : sendMessage.getReceiveMessages()) {
			addresseeIds.add(receiveMessage.getAddresseeId());
			addresseeNames.add(receiveMessage.getAddresseeName());
		}
		sendMessageForm.setAddresseeIds(addresseeIds);
		sendMessageForm.setAddresseeNames(addresseeNames);
		return sendMessageForm;
	}
	
	/**
	 * 
	 * convert:赋值WserviceForm对象.
	 * 
	 * @author xiaobin
	 * @param Announces
	 * @return AnnouncesForm
	 */
	public static AnnouncesForm convert(Announces announces) {
		
       if(null==announces){
    	   return null;
       }
       AnnouncesForm form = new AnnouncesForm();
       BeanUtils.copyProperties(announces, form);
       form.setCreateTime(announces.getCreateTime().toDate());
       if(null!=announces.getDrawer()){
    	   form.setType(announces.getDrawer().getId());
    	   form.setTypeName(announces.getDrawer().getName());
       }
       if(null!=announces.getUser()){
          form.setCreateId(announces.getUser().getId());
          form.setCreateName(announces.getUser().getUsername());
       }
	   return form;
	   
	}

}
